import Vue from 'vue'
import Vuex from 'vuex'
// vuex数据持久化解决方案
// 1.手动添加与监听localStorage数据变化
// 2.再vuex中引入persistedstate插件
// vuex-persistedstate 默认把数据存储localStorage
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    login:false,
    musicData:{
      coverImgUrl:""
    },
    musiclist:{
      coverImgUrl:""
    },
    userid:"",
    historylist:[],
    userlikelist:[]
  },
  mutations: {
    setLogin(state){
      state.login = true;
    },
    delLogin(state){
      state.login = false;
    },
    musicDatafun(state,obj){
      state.musicData = obj
    },
    musicListfun(state,obj){
      state.musiclist = obj
    },
    setuserid(state,data){
      state.userid = data
    },
    deluserid(state){
      state.userid = ""
    },
    sethistorylist(state,data){
      state.historylist = data
    },
    setuserlikelist(state,data){
      state.userlikelist = data
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [createPersistedState({
    storage:window.sessionStorage
  })]
})
